#include <iostream>
#include <set>
#include <unordered_map>
#include <string>
using namespace std;

unordered_map<string,set<int>> mp;
int main()
{
	int N;cin >> N;
	for(int i = 1; i<=N;i++)
	{
		int l;cin >> l;
		while(l--)
		{
			string s; cin >> s;
			mp[s].insert(i);
		}
	}
	 int m; cin >> m;
	while(m--)
	{
		string s; cin >> s;
		for(auto i : mp[s])
		{
			cout << i <<" ";
		}
		cout << endl;
	}
	return 0;
 } 
